// pages/report/report.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    reportObj: {},
    tabdex:"",
    popshow:false,
    tablist:[
      { 
        types: "所有人", 
        list: [
          { items: "父亲", checked: false }, 
          { items: "父亲", checked: false },
          { items: "我", checked: false },
        ]
      }, {
        types: "报告类型",
        list: [
          { items: "检验报告", checked: false },
          { items: "基因报告", checked: false },
          { items: "体检报告", checked: false },
        ]
      }, {
        types: "解读状态",
        list: [
          { items: "未解读", checked: false },
          { items: "已解读", checked: false },
        ]
      },
    ],
    //states 0 检验报告  1  基因报告  2  体检报告
    sicklist:[
      {
        headimg:"../../../images/xzadd.png",
        names:"张三",
        sex:"男",
        age:"23",
        times:"2019年12月8日",
        hospital:"山西省白求恩医院",
        numbers:"8529638525623",
        states:0,
      }, {
        headimg: "../../../images/xzadd.png",
        names: "张三",
        sex: "男",
        age: "23",
        times: "2019年12月8日",
        hospital: "山西省白求恩医院",
        numbers: "8529638525623",
        states: 1,
      }, {
        headimg: "../../../images/xzadd.png",
        names: "张三",
        sex: "男",
        age: "23",
        times: "2019年12月8日",
        hospital: "山西省白求恩医院",
        numbers: "8529638525623",
        states: 2,
      },
    ],
  },
  tabbtn(e){
    if (e.currentTarget.dataset.dex === this.data.tabdex){
      this.setData({
        popshow: false,
        tabdex: ""
      })
    }else{
      this.setData({
        popshow: true,
        tabdex: e.currentTarget.dataset.dex
      })
    }
  },
  itemchecked(e) {
    let arrs = this.data.tablist, i = this.data.tabdex, dex = e.currentTarget.dataset.dex
    arrs[i].list.map(item => {
      item.checked = false
    })
    arrs[i].types = arrs[i].list[dex].items
    arrs[i].list[dex].checked = true
    this.setData({
      tablist: arrs,
      popshow: false,
      tabdex: ""
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var that = this
    var openid = wx.getStorageSync('openid')
    app.util.request({
      'url': 'entry/wxapp/Allmyjiaren',
      data: {
        openid: openid,
      },
      success: function(res) {
        //console.log(res)
        var items = that.data.items
        items = items.concat(res.data.data)
        that.setData({
          items: items
        })
      }
    })
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    this.getAlltijianbaogao()
  },



  //查看报告
  reportDetailClick: function(e) {
    console.log(e)
    var hzid = e.target.dataset.hzid
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/report_detail/report_detail?hzid=' + hzid,
    })
  },
  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  //查询我的所有体检报告
  getAlltijianbaogao: function() {
    var that = this
    app.util.request({
      'url': 'entry/wxapp/Alltijianbaogao',
      data: {
        useropenid: wx.getStorageSync('openid'),
        hzid: 0
      },
      success: function(res) {
        console.log(res)
        var reportObj = that.data.reportObj
        reportObj["reportArr_0"] = res.data.data
        that.setData({
          reportObj: reportObj
        })
      }
    })
  }
})